package blog.service.impl;

import blog.common.Result;
import blog.entity.Action;
import blog.entity.User;
import blog.entity.Video;
import blog.mapper.UserMapper;
import blog.mapper.VideoMapper;
import blog.service.UserService;
import blog.service.VideoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    @Autowired
    private VideoMapper videoMapper;

    @Override
    public List<Integer> getVideoIdList(String videoName) {
        //先根据视频名字查询出多个视频id
        LambdaQueryWrapper<Video> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.like(Video::getName, videoName);
        wrapper1.select(Video::getId);
        Page<Video> videoPage = new Page<>(1, 100);
        Page<Video> videoPage1 = videoMapper.selectPage(videoPage, wrapper1);
        //再根据视频id查询出多个用户行为
        if (videoPage1.getRecords().size() == 0) {
            return null;
        }
        //将多个视频id放入list集合中
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < videoPage1.getRecords().size(); i++) {
            list.add(videoPage1.getRecords().get(i).getId());
        }
        return list;
    }
}